home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 August: Tool Chest / Apple_Developer_Group_August_1996_Tool_Chest.iso / Sample Code / Snippets / Sound / SampleRateAvail / SampleRateAvail.c next >
Encoding:
C/C++ Source or Header  |  1995-03-14  |  2.5 KB  |  91 lines  |  [TEXT/MPS ]

  1. /*****************************************************************************************
  2.      Snippet:            SampleRateAvail
  3.      
  4.      Description:        This snippet checks for the number of sample rates available on 
  5.                         a given Mac and lists those rates.
  6.                          
  7.      Programmer:            Kevin Mellander
  8.      Organization:        Apple Computer, Inc.
  9.      Department            Developer Technical Support, DTS
  10.      Language/Envir.        MPW C version 3.3.1
  11.      Date Created        11/29/94                              
  12.  
  13.  *****************************************************************************************/
  14. #include <SoundInput.h>
  15. #include <ToolUtils.h>
  16. #include <Types.h>
  17. #include <stdio.h>
  18.  
  19. struct soundRateData{
  20.         short numberOfRatesSupported;
  21.         Handle ratesSupported;
  22.     } soundRateInfo;
  23.  
  24. void main()
  25. {
  26.     OSErr    soundErr = 0;
  27.     long    mySIRefNum;
  28.     short    setSoundMeterState = 1;
  29.     Fixed     *myFixedPointer;
  30.     Fixed     myFixedVariable;
  31.     register unsigned long loopCounter;
  32.     
  33.     soundRateInfo.numberOfRatesSupported = 0;
  34.     soundRateInfo.ratesSupported = nil;
  35.     
  36.         
  37.     //Open the sound input device
  38.     soundErr = SPBOpenDevice("\p",siWritePermission,&mySIRefNum);
  39.     if (soundErr != noErr)
  40. {
  41.         DebugStr("\p Failure at call to SPBOpenDevice.");
  42.         ExitToShell();
  43. }
  44.         
  45.     //Get the number of rates supported
  46.     soundErr = SPBGetDeviceInfo(mySIRefNum,siSampleRateAvailable,(Ptr) &soundRateInfo);
  47.     if (soundErr != noErr)
  48.         DebugStr("\p Failure at call to SPBSetDeviceInfo set to 0");
  49.     else
  50.         printf("The number of sample rates supported by this recording device is %d \n \n And the sample rates supported are: \n", soundRateInfo.numberOfRatesSupported);
  51.     
  52.     //Now parse our list of sample rates to determine which are supported 
  53.     myFixedPointer = (Fixed *)(*(soundRateInfo.ratesSupported))    ;
  54.     
  55.     for(loopCounter=0; loopCounter < soundRateInfo.numberOfRatesSupported; loopCounter++)
  56.     {
  57.         myFixedVariable = *myFixedPointer;
  58.         switch (myFixedVariable)
  59.         {
  60.             case 0xAC440000:
  61.                 printf("\t44.1 kHz\n");
  62.                 break;
  63.             case 0x56EE8BA3:
  64.                 printf("\t22.254 kHz\n");
  65.                 break;
  66.             case 0x56220000:
  67.                 printf("\t22.050 kHz\n");
  68.                 break;
  69.             case 0x2B7745D1:
  70.                 printf("\t11.127 kHz\n");
  71.                 break;
  72.             case 0x2B110000:
  73.                 printf("\t11.025 kHz\n");
  74.                 break;
  75.             case 0x1CFA2E8B:
  76.                 printf("\t7.418 kHz\n");
  77.                 break;
  78.             case 0x15BBA2E8:
  79.                 printf("\t5.563 kHz\n");
  80.                 break;
  81.             default:
  82.                 printf("I do not have a listing for this sample rate\n");
  83.         }
  84.         myFixedPointer++;
  85.     }
  86.     
  87.     //We're done so close the device
  88.     soundErr = SPBCloseDevice(mySIRefNum);
  89.     if (soundErr != noErr)
  90.         DebugStr("\p Failure at call to SPBCloseDevice");
  91. }